#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

int n;
long long c[MAXN],f[MAXN],g[MAXN],ans = -1ll * MAXN*MAXN,tot = 0;

int main (){
	scanf("%d",&n); for(int i = 1;i <= n;i++) scanf("%lld",&c[i]);
	f[0] = ans;
	for(int i = 1;i <= n;i++){
		if(tot < 0) tot = 0;
		tot = tot + c[i];
		f[i] = max(f[i-1],tot);
	}
	g[n+1] = ans;
	tot = 0;
	for(int i = n;i >= 1;i--){
		if(tot < 0) tot = 0;tot = tot + c[i];
		g[i] = max(g[i+1],tot);
	}
	for(int i = 1;i < n;i++) ans = max(ans,f[i] + g[i+1]);
	printf("%lld\n",ans);return 0;
}
